﻿using System;

namespace LearnFile2
{
    class Program
    {
        static void Main(string[] args)
        {
            //可用的赋值运算符：
            int a = 21;
            int c;

            c = a;
            Console.WriteLine("Line 1 - =  c 的值 = {0}", c);

            c += a;
            Console.WriteLine("Line 2 - += c 的值 = {0}", c);

            c -= a;
            Console.WriteLine("Line 3 - -=  c 的值 = {0}", c);

            c *= a;
            Console.WriteLine("Line 4 - *=  c 的值 = {0}", c);

            c /= a;
            Console.WriteLine("Line 5 - /=  c 的值 = {0}", c);

            c = 200;
            c %= a;
            Console.WriteLine("Line 6 - %=  c 的值 = {0}", c);

            c <<= 2;
            Console.WriteLine("Line 7 - <<=  c 的值 = {0}", c);

            c >>= 2;//右移且赋值运算符
            Console.WriteLine("Line 8 - >>=  c 的值 = {0}", c);

            c &= 2;//按位与且赋值运算符
            Console.WriteLine("Line 9 - &=  c 的值 = {0}", c);

            c ^= 2;//按位异或且赋值运算符
            Console.WriteLine("Line 10 - ^=  c 的值 = {0}", c);

            c |= 2;//按位或且赋值运算符
            Console.WriteLine("Line 11 - |=  c 的值 = {0}", c);
            Console.ReadLine();


            //重要的运算符，包括 sizeof、typeof 和 ? :。
            /* sizeof 运算符的实例 */
            Console.WriteLine("int 的大小是 {0}", sizeof(int));
            Console.WriteLine("short 的大小是 {0}", sizeof(short));
            Console.WriteLine("double 的大小是 {0}", sizeof(double));

            /* 三元运算符的实例 */
            int d, e;
            d = 10;
            e = (d == 1) ? 20 : 30;
            Console.WriteLine("e 的值是 {0}", e);

            e = (d == 10) ? 20 : 30;
            Console.WriteLine("e 的值是 {0}", e);
            Console.ReadLine();

        }
    }
}
